<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Byte Arrays</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="index.html" title="GLib Reference Manual">
<link rel="up" href="glib-data-types.html" title="GLib Data Types">
<link rel="prev" href="glib-Pointer-Arrays.html" title="Pointer Arrays">
<link rel="next" href="glib-Balanced-Binary-Trees.html" title="Balanced Binary Trees">
<meta name="generator" content="GTK-Doc V1.17 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
<tr valign="middle">
<td><a accesskey="p" href="glib-Pointer-Arrays.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="glib-data-types.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GLib Reference Manual</th>
<td><a accesskey="n" href="glib-Balanced-Binary-Trees.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr>
<tr><td colspan="5" class="shortcuts">
<a href="#glib-Byte-Arrays.synopsis" class="shortcut">Top</a>
                   | 
                  <a href="#glib-Byte-Arrays.description" class="shortcut">Description</a>
</td></tr>
</table>
<div class="refentry">
<a name="glib-Byte-Arrays"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle"><a name="glib-Byte-Arrays.top_of_page"></a>Byte Arrays</span></h2>
<p>Byte Arrays — arrays of bytes, which grow automatically as
                    elements are added</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<a name="glib-Byte-Arrays.synopsis"></a><h2>Synopsis</h2>
<pre class="synopsis">
#include &lt;glib.h&gt;

struct              <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray">GByteArray</a>;
<a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="returnvalue">GByteArray</span></a> *        <a class="link" href="glib-Byte-Arrays.html#g-byte-array-new" title="g_byte_array_new ()">g_byte_array_new</a>                    (<em class="parameter"><code><span class="type">void</span></code></em>);
<a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="returnvalue">GByteArray</span></a> *        <a class="link" href="glib-Byte-Arrays.html#g-byte-array-sized-new" title="g_byte_array_sized_new ()">g_byte_array_sized_new</a>              (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="type">guint</span></a> reserved_size</code></em>);
<a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="returnvalue">GByteArray</span></a> *        <a class="link" href="glib-Byte-Arrays.html#g-byte-array-ref" title="g_byte_array_ref ()">g_byte_array_ref</a>                    (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>);
<span class="returnvalue">void</span>                <a class="link" href="glib-Byte-Arrays.html#g-byte-array-unref" title="g_byte_array_unref ()">g_byte_array_unref</a>                  (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>);
<a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="returnvalue">GByteArray</span></a> *        <a class="link" href="glib-Byte-Arrays.html#g-byte-array-append" title="g_byte_array_append ()">g_byte_array_append</a>                 (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>,
                                                         <em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#guint8" title="guint8"><span class="type">guint8</span></a> *data</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="type">guint</span></a> len</code></em>);
<a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="returnvalue">GByteArray</span></a> *        <a class="link" href="glib-Byte-Arrays.html#g-byte-array-prepend" title="g_byte_array_prepend ()">g_byte_array_prepend</a>                (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>,
                                                         <em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#guint8" title="guint8"><span class="type">guint8</span></a> *data</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="type">guint</span></a> len</code></em>);
<a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="returnvalue">GByteArray</span></a> *        <a class="link" href="glib-Byte-Arrays.html#g-byte-array-remove-index" title="g_byte_array_remove_index ()">g_byte_array_remove_index</a>           (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="type">guint</span></a> index_</code></em>);
<a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="returnvalue">GByteArray</span></a> *        <a class="link" href="glib-Byte-Arrays.html#g-byte-array-remove-index-fast" title="g_byte_array_remove_index_fast ()">g_byte_array_remove_index_fast</a>      (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="type">guint</span></a> index_</code></em>);
<a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="returnvalue">GByteArray</span></a> *        <a class="link" href="glib-Byte-Arrays.html#g-byte-array-remove-range" title="g_byte_array_remove_range ()">g_byte_array_remove_range</a>           (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="type">guint</span></a> index_</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="type">guint</span></a> length</code></em>);
<span class="returnvalue">void</span>                <a class="link" href="glib-Byte-Arrays.html#g-byte-array-sort" title="g_byte_array_sort ()">g_byte_array_sort</a>                   (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Doubly-Linked-Lists.html#GCompareFunc" title="GCompareFunc ()"><span class="type">GCompareFunc</span></a> compare_func</code></em>);
<span class="returnvalue">void</span>                <a class="link" href="glib-Byte-Arrays.html#g-byte-array-sort-with-data" title="g_byte_array_sort_with_data ()">g_byte_array_sort_with_data</a>         (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Doubly-Linked-Lists.html#GCompareDataFunc" title="GCompareDataFunc ()"><span class="type">GCompareDataFunc</span></a> compare_func</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>);
<a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="returnvalue">GByteArray</span></a> *        <a class="link" href="glib-Byte-Arrays.html#g-byte-array-set-size" title="g_byte_array_set_size ()">g_byte_array_set_size</a>               (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="type">guint</span></a> length</code></em>);
<a class="link" href="glib-Basic-Types.html#guint8" title="guint8"><span class="returnvalue">guint8</span></a> *            <a class="link" href="glib-Byte-Arrays.html#g-byte-array-free" title="g_byte_array_free ()">g_byte_array_free</a>                   (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="type">gboolean</span></a> free_segment</code></em>);
</pre>
</div>
<div class="refsect1">
<a name="glib-Byte-Arrays.description"></a><h2>Description</h2>
<p>
<a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> is based on <a class="link" href="glib-Arrays.html#GArray" title="struct GArray"><span class="type">GArray</span></a>, to provide arrays of bytes which
grow automatically as elements are added.
</p>
<p>
To create a new <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> use <a class="link" href="glib-Byte-Arrays.html#g-byte-array-new" title="g_byte_array_new ()"><code class="function">g_byte_array_new()</code></a>.
</p>
<p>
To add elements to a <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>, use <a class="link" href="glib-Byte-Arrays.html#g-byte-array-append" title="g_byte_array_append ()"><code class="function">g_byte_array_append()</code></a>, and
<a class="link" href="glib-Byte-Arrays.html#g-byte-array-prepend" title="g_byte_array_prepend ()"><code class="function">g_byte_array_prepend()</code></a>.
</p>
<p>
To set the size of a <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>, use <a class="link" href="glib-Byte-Arrays.html#g-byte-array-set-size" title="g_byte_array_set_size ()"><code class="function">g_byte_array_set_size()</code></a>.
</p>
<p>
To free a <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>, use <a class="link" href="glib-Byte-Arrays.html#g-byte-array-free" title="g_byte_array_free ()"><code class="function">g_byte_array_free()</code></a>.
</p>
<p>
</p>
<div class="example">
<a name="id420227"></a><p class="title"><b>Example 23. Using a <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a></b></p>
<div class="example-contents">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="usertype">GByteArray</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">gbarray</span><span class="symbol">;</span>
<span class="usertype">gint</span><span class="normal"> i</span><span class="symbol">;</span>

<span class="normal">gbarray </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="glib-Byte-Arrays.html#g-byte-array-new">g_byte_array_new</a></span><span class="normal"> </span><span class="symbol">();</span>
<span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">i </span><span class="symbol">=</span><span class="normal"> </span><span class="number">0</span><span class="symbol">;</span><span class="normal"> i </span><span class="symbol">&lt;</span><span class="normal"> </span><span class="number">10000</span><span class="symbol">;</span><span class="normal"> i</span><span class="symbol">++)</span>
<span class="normal">  </span><span class="function"><a href="glib-Byte-Arrays.html#g-byte-array-append">g_byte_array_append</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">gbarray</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">(</span><span class="normal"><a href="glib-Basic-Types.html#guint8">guint8</a></span><span class="symbol">*)</span><span class="normal"> </span><span class="string">"abcd"</span><span class="symbol">,</span><span class="normal"> </span><span class="number">4</span><span class="symbol">);</span>

<span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">i </span><span class="symbol">=</span><span class="normal"> </span><span class="number">0</span><span class="symbol">;</span><span class="normal"> i </span><span class="symbol">&lt;</span><span class="normal"> </span><span class="number">10000</span><span class="symbol">;</span><span class="normal"> i</span><span class="symbol">++)</span>
<span class="normal">  </span><span class="cbracket">{</span>
<span class="normal">    </span><span class="function"><a href="glib-Testing.html#g-assert">g_assert</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">gbarray</span><span class="symbol">-&gt;</span><span class="normal">data</span><span class="symbol">[</span><span class="number">4</span><span class="symbol">*</span><span class="normal">i</span><span class="symbol">]</span><span class="normal"> </span><span class="symbol">==</span><span class="normal"> </span><span class="string">'a'</span><span class="symbol">);</span>
<span class="normal">    </span><span class="function"><a href="glib-Testing.html#g-assert">g_assert</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">gbarray</span><span class="symbol">-&gt;</span><span class="normal">data</span><span class="symbol">[</span><span class="number">4</span><span class="symbol">*</span><span class="normal">i</span><span class="symbol">+</span><span class="number">1</span><span class="symbol">]</span><span class="normal"> </span><span class="symbol">==</span><span class="normal"> </span><span class="string">'b'</span><span class="symbol">);</span>
<span class="normal">    </span><span class="function"><a href="glib-Testing.html#g-assert">g_assert</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">gbarray</span><span class="symbol">-&gt;</span><span class="normal">data</span><span class="symbol">[</span><span class="number">4</span><span class="symbol">*</span><span class="normal">i</span><span class="symbol">+</span><span class="number">2</span><span class="symbol">]</span><span class="normal"> </span><span class="symbol">==</span><span class="normal"> </span><span class="string">'c'</span><span class="symbol">);</span>
<span class="normal">    </span><span class="function"><a href="glib-Testing.html#g-assert">g_assert</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">gbarray</span><span class="symbol">-&gt;</span><span class="normal">data</span><span class="symbol">[</span><span class="number">4</span><span class="symbol">*</span><span class="normal">i</span><span class="symbol">+</span><span class="number">3</span><span class="symbol">]</span><span class="normal"> </span><span class="symbol">==</span><span class="normal"> </span><span class="string">'d'</span><span class="symbol">);</span>
<span class="normal">  </span><span class="cbracket">}</span>

<span class="function"><a href="glib-Byte-Arrays.html#g-byte-array-free">g_byte_array_free</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">gbarray</span><span class="symbol">,</span><span class="normal"> <a href="glib-Standard-Macros.html#TRUE:CAPS">TRUE</a></span><span class="symbol">);</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

</div>
<p><br class="example-break">
</p>
</div>
<div class="refsect1">
<a name="glib-Byte-Arrays.details"></a><h2>Details</h2>
<div class="refsect2">
<a name="GByteArray"></a><h3>struct GByteArray</h3>
<pre class="programlisting">struct GByteArray {
  guint8 *data;
  guint	  len;
};
</pre>
<p>
The <span class="structname">GByteArray</span> struct allows access to the
public fields of a <span class="structname">GByteArray</span>.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><a class="link" href="glib-Basic-Types.html#guint8" title="guint8"><span class="type">guint8</span></a> *<em class="structfield"><code><a name="GByteArray.data"></a>data</code></em>;</span></p></td>
<td>a pointer to the element data. The data may be moved as
elements are added to the <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
<tr>
<td><p><span class="term"><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="type">guint</span></a> <em class="structfield"><code><a name="GByteArray.len"></a>len</code></em>;</span></p></td>
<td>the number of elements in the <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="g-byte-array-new"></a><h3>g_byte_array_new ()</h3>
<pre class="programlisting"><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="returnvalue">GByteArray</span></a> *        g_byte_array_new                    (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
<p>
Creates a new <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> with a reference count of 1.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the new <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="g-byte-array-sized-new"></a><h3>g_byte_array_sized_new ()</h3>
<pre class="programlisting"><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="returnvalue">GByteArray</span></a> *        g_byte_array_sized_new              (<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="type">guint</span></a> reserved_size</code></em>);</pre>
<p>
Creates a new <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> with <em class="parameter"><code>reserved_size</code></em> bytes preallocated.
This avoids frequent reallocation, if you are going to add many
bytes to the array. Note however that the size of the array is still
0.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>reserved_size</code></em> :</span></p></td>
<td>number of bytes preallocated.</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the new <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="g-byte-array-ref"></a><h3>g_byte_array_ref ()</h3>
<pre class="programlisting"><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="returnvalue">GByteArray</span></a> *        g_byte_array_ref                    (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>);</pre>
<p>
Atomically increments the reference count of <em class="parameter"><code>array</code></em> by one. This
function is MT-safe and may be called from any thread.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>array</code></em> :</span></p></td>
<td>A <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>The passed in <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.22</p>
</div>
<hr>
<div class="refsect2">
<a name="g-byte-array-unref"></a><h3>g_byte_array_unref ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>                g_byte_array_unref                  (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>);</pre>
<p>
Atomically decrements the reference count of <em class="parameter"><code>array</code></em> by one. If the
reference count drops to 0, all memory allocated by the array is
released. This function is MT-safe and may be called from any
thread.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>array</code></em> :</span></p></td>
<td>A <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr></tbody>
</table></div>
<p class="since">Since 2.22</p>
</div>
<hr>
<div class="refsect2">
<a name="g-byte-array-append"></a><h3>g_byte_array_append ()</h3>
<pre class="programlisting"><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="returnvalue">GByteArray</span></a> *        g_byte_array_append                 (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>,
                                                         <em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#guint8" title="guint8"><span class="type">guint8</span></a> *data</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="type">guint</span></a> len</code></em>);</pre>
<p>
Adds the given bytes to the end of the <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>. The array will
grow in size automatically if necessary.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>array</code></em> :</span></p></td>
<td>a <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>data</code></em> :</span></p></td>
<td>the byte data to be added.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>len</code></em> :</span></p></td>
<td>the number of bytes to add.</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="g-byte-array-prepend"></a><h3>g_byte_array_prepend ()</h3>
<pre class="programlisting"><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="returnvalue">GByteArray</span></a> *        g_byte_array_prepend                (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>,
                                                         <em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#guint8" title="guint8"><span class="type">guint8</span></a> *data</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="type">guint</span></a> len</code></em>);</pre>
<p>
Adds the given data to the start of the <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>. The array will
grow in size automatically if necessary.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>array</code></em> :</span></p></td>
<td>a <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>data</code></em> :</span></p></td>
<td>the byte data to be added.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>len</code></em> :</span></p></td>
<td>the number of bytes to add.</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="g-byte-array-remove-index"></a><h3>g_byte_array_remove_index ()</h3>
<pre class="programlisting"><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="returnvalue">GByteArray</span></a> *        g_byte_array_remove_index           (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="type">guint</span></a> index_</code></em>);</pre>
<p>
Removes the byte at the given index from a <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>. The
following bytes are moved down one place.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>array</code></em> :</span></p></td>
<td>a <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>index_</code></em> :</span></p></td>
<td>the index of the byte to remove.</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="g-byte-array-remove-index-fast"></a><h3>g_byte_array_remove_index_fast ()</h3>
<pre class="programlisting"><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="returnvalue">GByteArray</span></a> *        g_byte_array_remove_index_fast      (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="type">guint</span></a> index_</code></em>);</pre>
<p>
Removes the byte at the given index from a <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>. The last
element in the array is used to fill in the space, so this function
does not preserve the order of the <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>. But it is faster
than <a class="link" href="glib-Byte-Arrays.html#g-byte-array-remove-index" title="g_byte_array_remove_index ()"><code class="function">g_byte_array_remove_index()</code></a>.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>array</code></em> :</span></p></td>
<td>a <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>index_</code></em> :</span></p></td>
<td>the index of the byte to remove.</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="g-byte-array-remove-range"></a><h3>g_byte_array_remove_range ()</h3>
<pre class="programlisting"><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="returnvalue">GByteArray</span></a> *        g_byte_array_remove_range           (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="type">guint</span></a> index_</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="type">guint</span></a> length</code></em>);</pre>
<p>
Removes the given number of bytes starting at the given index from a
<a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.  The following elements are moved to close the gap.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>array</code></em> :</span></p></td>
<td>a <em class="parameter"><code>GByteArray</code></em>.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>index_</code></em> :</span></p></td>
<td>the index of the first byte to remove.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>length</code></em> :</span></p></td>
<td>the number of bytes to remove.</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.4</p>
</div>
<hr>
<div class="refsect2">
<a name="g-byte-array-sort"></a><h3>g_byte_array_sort ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>                g_byte_array_sort                   (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Doubly-Linked-Lists.html#GCompareFunc" title="GCompareFunc ()"><span class="type">GCompareFunc</span></a> compare_func</code></em>);</pre>
<p>
Sorts a byte array, using <em class="parameter"><code>compare_func</code></em> which should be a
<code class="function">qsort()</code>-style comparison function (returns less than zero for first
arg is less than second arg, zero for equal, greater than zero if
first arg is greater than second arg).
</p>
<p>
If two array elements compare equal, their order in the sorted array
is undefined. If you want equal elements to keep their order &amp;<span class="type">8211</span>; i.e.
you want a stable sort &amp;<span class="type">8211</span>; you can write a comparison function that,
if two elements would otherwise compare equal, compares them by
their addresses.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>array</code></em> :</span></p></td>
<td>a <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>compare_func</code></em> :</span></p></td>
<td>comparison function.</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="g-byte-array-sort-with-data"></a><h3>g_byte_array_sort_with_data ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>                g_byte_array_sort_with_data         (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Doubly-Linked-Lists.html#GCompareDataFunc" title="GCompareDataFunc ()"><span class="type">GCompareDataFunc</span></a> compare_func</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> user_data</code></em>);</pre>
<p>
Like <a class="link" href="glib-Byte-Arrays.html#g-byte-array-sort" title="g_byte_array_sort ()"><code class="function">g_byte_array_sort()</code></a>, but the comparison function takes an extra
user data argument.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>array</code></em> :</span></p></td>
<td>a <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>compare_func</code></em> :</span></p></td>
<td>comparison function.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>user_data</code></em> :</span></p></td>
<td>data to pass to <em class="parameter"><code>compare_func</code></em>.</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="g-byte-array-set-size"></a><h3>g_byte_array_set_size ()</h3>
<pre class="programlisting"><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="returnvalue">GByteArray</span></a> *        g_byte_array_set_size               (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#guint" title="guint"><span class="type">guint</span></a> length</code></em>);</pre>
<p>
Sets the size of the <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>, expanding it if necessary.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>array</code></em> :</span></p></td>
<td>a <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>length</code></em> :</span></p></td>
<td>the new size of the <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="g-byte-array-free"></a><h3>g_byte_array_free ()</h3>
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#guint8" title="guint8"><span class="returnvalue">guint8</span></a> *            g_byte_array_free                   (<em class="parameter"><code><a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> *array</code></em>,
                                                         <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="type">gboolean</span></a> free_segment</code></em>);</pre>
<p>
Frees the memory allocated by the <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>. If <em class="parameter"><code>free_segment</code></em> is
<a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> it frees the actual byte data. If the reference count of
<em class="parameter"><code>array</code></em> is greater than one, the <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a> wrapper is preserved but
the size of <em class="parameter"><code>array</code></em> will be set to zero.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>array</code></em> :</span></p></td>
<td>a <a class="link" href="glib-Byte-Arrays.html#GByteArray" title="struct GByteArray"><span class="type">GByteArray</span></a>.</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>free_segment</code></em> :</span></p></td>
<td>if <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> the actual byte data is freed as well.</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the element data if <em class="parameter"><code>free_segment</code></em> is <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a>, otherwise
<a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>.  The element data should be freed using <a class="link" href="glib-Memory-Allocation.html#g-free" title="g_free ()"><code class="function">g_free()</code></a>.</td>
</tr>
</tbody>
</table></div>
</div>
</div>
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.17</div>
</body>
</html>